<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="sidebar.collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <!-- v-permiss="item.permiss" -->
        <template v-if="item.subs">
          <el-sub-menu :index="item.index" :key="item.index">
            <template #title>
              <el-icon>
                <component :is="item.icon"></component>
              </el-icon>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-sub-menu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template #title>{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                >
                  {{ threeItem.title }}
                </el-menu-item>
              </el-sub-menu>
              <el-menu-item v-else :index="subItem.index">
                {{ subItem.title }}
              </el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <el-icon>
              <component :is="item.icon"></component>
            </el-icon>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue"
import { useSidebarStore } from "../store/sidebar"
import { useRoute } from "vue-router"

const items: any = ref([
  {
    icon: "Edit",
    index: "/business",
    title: "业务模块",
    subs: [
      {
        index: "/business/latestData",
        title: "最新数据"
      },
      {
        index: "/business/lineAnalyze",
        title: "线损分析"
      },
      {
        index: "/business/zoneManage",
        title: "台区管理"
      }
    ]
  },
  {
    icon: "Management",
    index: "/tool",
    title: "设备管理",
    subs: [
      {
        index: "/tool/import",
        title: "设备基础数据导入"
      },
      {
        index: "/tool/correct",
        title: "设备校准"
      }
    ]
  },
  {
    icon: "Tools",
    index: "/system",
    title: "系统设置",
    subs: [
      {
        index: "/system/org",
        title: "区域管理"
      },
      {
        index: "/system/user",
        title: "用户管理"
      },
      {
        index: "/system/role",
        title: "角色管理"
      },
      // {
      //   index: "/system/configure",
      //   title: "配置关系数据"
      // },
      {
        index: "/system/configUser",
        title: "配置数据"
      }
    ]
  },
  // {
  //   icon: "Tools",
  //   index: "/system",
  //   title: "系统设置",
  //   subs: [
  //     {
  //       index: "/system/org",
  //       title: "区域管理",
  //     },
  //     {
  //       index: "/system/user",
  //       title: "用户管理",
  //     },
  //   ],
  // },
])

const route = useRoute()
const onRoutes = computed(() => {
  return route.path
})

const sidebar = useSidebarStore()
// const user = JSON.parse(sessionStorage.getItem("user"))
// if (user?.orgId == 1) {
//   items.value.push({
//     icon: "Tools",
//     index: "/system",
//     title: "系统设置",
//     subs: [
//       {
//         index: "/system/org",
//         title: "区域管理"
//       },
//       {
//         index: "/system/user",
//         title: "用户管理"
//       },
//       {
//         index: "/system/role",
//         title: "角色管理"
//       },
//       {
//         index: "/system/configure",
//         title: "配置数据"
//       }
//     ]
//   })
// }
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>
